<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class announcement_service{
	private $CI;
	function __construct() { 
		$this->CI = &get_instance();
		$this->CI->load->model('Admin_model');
		$this->CI->load->model('Announcement_model');
		$this->CI->load->library('ProjectService/admin_service');
	}

	/**  
	* 根据用户角色，取出所有他可以看到的公告
	* @access public 
	* @param  $admin_id 用户id
	* @param  $is_del 是否要拿出删除的，默认false
	* @return array
	*/  
	public function getAnnouncementByAdminId($admin_id,$is_del=false) {
		//先取出id的所有角色
		$admin=$this->CI->admin_service->getAdminById($admin_id);
		if($admin['sub_role_id']&&$admin['sub_role_id']!=''){
			$role_id_str=$admin['role_id'].','.$admin['sub_role_id'];
		}
		else{
			$role_id_str=$admin['role_id'];
		}

		if(!$is_del){
			$connar['where']=$this->CI->sqlEscape(" F_checkInArray(??,role_id_str)=1 and status=?? ",array($role_id_str,CommonStatus::UnDeleted[XPHEnum::Value]));
		}
		else{
			$connar['where']=$this->sqlEscape(" F_checkInArray(??,role_id_str)=1 ",array($role_id_str));
		}
		
		$announcement=$this->CI->Announcement_model->get_list_full($connar);
		return $announcement;
	}
	
	
}